// pages/seckill/seckill.js
const app = getApp()
var wh = require("../../utils/wh.js");
Page({

  /**
   * 页面的初始数据
   */ 
  data: {
    imgUrls: [
      { id: 1, img: '../../img/banner.png' },
      { id: 2, img: '../../img/banner.png' },
      { id: 3, img: '../../img/banner.png' },
    ],
    shop: [],
    page: 1,
    page_size: 5,
    no_data: 0, 
    onearth: false, // 是否已经到达底部
    have: true,
  },
  // 轮播跳转
  swiper(e) {
    wx.navigateTo({
      url: e.currentTarget.dataset.url,
    })
  },
  // 导航轮播
  ban(){
    var that = this;
    wh.Post('/api/common.banner/get_list', {type:3}, function (res) {
      console.log(res)
      that.setData({
        imgUrls: res
      })
    });
  },
// 获取砍价列表
  getBarbainList(shop_id){
      let that = this;
      let page_size = this.data.page_size,
        no_data = this.data.no_data,
        page = this.data.page;
      if (no_data == 0) {
        wh.Post('/api/mall.bargain/lists', {
          page: page,
          page_num: page_size,
          shop_id: shop_id
        }, function (res) {
      console.log(res)
          let shop = that.data.shop.concat(res),
            count = res.length;
          console.log(res)
          if (page_size > count) {
            that.data.no_data = 1;
            if (shop.length >= 3) {
              that.setData({
                onearth: true
              })
            }
          }
          that.setData({
            shop: shop
          })
          if (that.data.shop.length == 0) {
            that.setData({
              have: false,
            });
          } else {
            that.setData({
              have: true,
            });
          }
        })
      }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getBarbainList(options.shop_id)
    this.ban()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let no_data = this.data.no_data,
      page = this.data.page,
      page_size = this.data.page_size;
    if (no_data == 0) {
      this.data.page = page + 1;
      this.getBarbainList()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})